﻿'Imports SetDefaultAudioEndpoint.CommandLineParser

Interface IExecutionOption

  Function TestSwitch(ByVal value As String) As Boolean
  Sub SetSwitch(ByVal value As String)
  Sub Execute(ByVal sound As WindowsSound)

End Interface

MustInherit Class ExecutionOption
  Implements IExecutionOption

  Private ReadOnly mySwitch As String

  Protected Sub New(ByVal switch As String)
    Me.mySwitch = switch
  End Sub

  Public MustOverride Sub Execute(ByVal sound As WindowsSound) Implements IExecutionOption.Execute
  Protected MustOverride Sub SetSwitchCore(ByVal value As String)

  Public Sub SetSwitch(ByVal value As String) Implements IExecutionOption.SetSwitch
    If (String.IsNullOrEmpty(value)) Then
      Throw New ArgumentNullException("value")
    End If

    Me.SetSwitchCore(value)
  End Sub

  Public Overridable Function TestSwitch(ByVal value As String) As Boolean Implements IExecutionOption.TestSwitch
    Return Me.mySwitch = value.Substring(1, 1).ToUpper(Globalization.CultureInfo.InvariantCulture)
  End Function
End Class

Class SetPlaybackDeviceByNameExecutionOption
  Inherits ExecutionOption

  Const Switch As String = "P"

  Private myPlaybackDeviceName As String

  Public Sub New()
    MyBase.new(Switch)
  End Sub

  Protected Overrides Sub SetSwitchCore(ByVal value As String)
    Me.myPlaybackDeviceName = value.Substring(2)
  End Sub

  Public Overrides Sub Execute(ByVal sound As WindowsSound)
    sound.SetDefaultAudioPlaybackEndpoint(Me.myPlaybackDeviceName)
    Me.WriteConsoleSuccess("playback", Me.myPlaybackDeviceName)
  End Sub
End Class

Class SetPlaybackDeviceByIndexExecutionOption
  Inherits ExecutionOption

  Const Switch As String = "K"
  'Private Switch As String() = {"K", "PlaybackIndex"}

  Private myPlaybackDeviceIndex As Integer

  Public Sub New()
    MyBase.new(Switch)
  End Sub

  Protected Overrides Sub SetSwitchCore(ByVal value As String)
    Me.myPlaybackDeviceIndex = CInt(value.Substring(2))
  End Sub

  Public Overrides Sub Execute(ByVal sound As WindowsSound)
    sound.SetDefaultAudioPlaybackEndpoint(Me.myPlaybackDeviceIndex)
    Me.WriteConsoleSuccess("playback", Me.myPlaybackDeviceIndex)
  End Sub
End Class

Class ExecutionOptionsList
  Inherits List(Of IExecutionOption)

End Class

'Public Class ExecutionOptionsDispatcher

'  Public Sub New()

'  End Sub

'  Public Sub Dispatch(ByVal options As ExecutionOptions)
'    'ByVal playbackDeviceName As String, ByVal recordingDeviceName As String
'    Dim items As ExecutionOptionsList

'    'For Each item In items.

'    'Next

'    Using sound As New WindowsSound
'      If (options.PlaybackDeviceIndex.HasValue) Then
'        sound.SetDefaultAudioPlaybackEndpoint(options.PlaybackDeviceIndex.Value)
'        Me.WriteConsoleSuccess("playback", options.PlaybackDeviceIndex.Value.ToString)
'      End If

'      'Me.SetDefaultAudioPlaybackDevice(sound, PlaybackDeviceName)
'      'Me.SetDefaultAudioRecordingDevice(sound, RecordingDeviceName)
'    End Using
'  End Sub

'  'Private Sub SetDefaultAudioPlaybackDevice(ByVal sound As WindowsSound, ByVal deviceName As String)
'  '  Me.SetDefaultAudioDevice("playback", deviceName, AddressOf sound.SetDefaultAudioPlaybackEndpoint)
'  'End Sub

'  'Private Sub SetDefaultAudioRecordingDevice(ByVal sound As WindowsSound, ByVal deviceName As String)
'  '  Me.SetDefaultAudioDevice("recording", deviceName, AddressOf sound.SetDefaultAudioRecordingEndpoint)
'  'End Sub

'  'Private Sub SetDefaultAudioDevice(ByVal deviceTypeName As String, ByVal deviceName As String, ByVal action As Action(Of String))
'  '  If (String.IsNullOrEmpty(deviceName)) Then
'  '    Return
'  '  End If

'  '  action.Invoke(deviceName)
'  '  Me.WriteConsoleSuccess(deviceTypeName, deviceName)
'  'End Sub

'End Class
